package com.eastmelon.tcp;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/**
 * @author Administrator 1.建立socket服务。指定要连接主机和端口
 *         2.获取socket流中的输出流，将数据写到该流中，通过网络发送给服务端 3.获取输入流，获取服务器反馈的数据，打印 4.关闭客户端资源
 */
public class TcpClient2 {
	public static void main(String[] args) throws Exception, IOException {
		Socket s = new Socket("127.0.0.1", 10003);
		OutputStream out = s.getOutputStream();
		out.write("服务器你好".getBytes());
		InputStream in = s.getInputStream();
		byte[] buf = new byte[2014];
		int len = in.read(buf);
		System.out.println(new String(buf, 0, len));
		s.close();
	}

}
